<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="utf-8"/>
    <title>anyOf</title>
    <link rel="stylesheet" id="theme-link" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <link rel="stylesheet" id="iconlib-link" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css">
    <script src="../../dist/jsoneditor.js"></script>
</head>
<body>

<div class="container">
    <h1>Test</h1>
    <label for="value">Value</label>
    <textarea class="form-control" id="value" rows="12" style="font-size: 12px; font-family: monospace;"></textarea>
    <button id='set-value'>Set Value</button>
    <div class='json-editor-container'></div>
</div>

<script>
  var jsonEditorContainer = document.querySelector('.json-editor-container')
  var value = document.querySelector('#value')
  var setValue = document.querySelector('#set-value')
  var schema = {
    'title': 'anyOf',
    'type': 'object',
    'properties': {
      'test': {
        'anyOf': [
          {
            'type': 'string',
            'title': 'Value, string',
            'const': 'test'
          },
          {
            'type': 'boolean',
            'title': 'Value, boolean',
            'const': true
          },
          {
            'type': 'array',
            'title': 'Value, array',
            'const': [0]
          },
          {
            'type': 'object',
            'title': 'Value, object',
            'required': ['test'],
            'const': { 'test': 'test' }
          },
          {
            'type': 'number',
            'title': 'Value, number',
            'const': 1.1
          },
          {
            'type': 'integer',
            'title': 'Value, integer',
            'const': 1.1
          },
          {
            'type': 'null',
            'title': 'Value, null'
          }
        ]
      }
    }
  }

  var editor = new JSONEditor(jsonEditorContainer, {
    schema: schema,
    theme: 'bootstrap4',
    show_errors: 'always',
    iconlib: 'fontawesome5',
    disable_collapse: true,
    disable_edit_json: true,
    disable_properties: true,
    keep_oneof_values: false
  })

  editor.on('change', function () {
    value.value = JSON.stringify(editor.getValue())
  })

  setValue.addEventListener('click', function () {
    editor.setValue(JSON.parse(value.value))
  })
</script>

</body>
</html>
